<template>
  <el-dialog
    title="进度详情"
    :visible="visible"
    width="900px"
    :before-close="handleClose"
  >
    <div class="box">
      <div class="left">
        <div class="header">
          <div class="title">章节目录</div>
        </div>
        <div
          v-for="(item, index) in chapterList"
          :key="item.id"
          class="item"
          :class="{ 'acitve-item': activeCharpter.id === item.id }"
          @click="clickCharpter(item)"
        >
          <div>{{ `第${index + 1}章 ${item.chapterName}` }}</div>
        </div>
      </div>
      <div class="right">
        <div class="header">
          <div class="title">课时目录</div>
        </div>
        <div
          v-for="(item, index) in activeCharpter.periodRespList"
          :key="item.id"
          class="item"
        >
          <div>{{ `第${index + 1}课时 ${item.periodName}` }}</div>
          <div>
            <span class="progress">{{ item.periodProgress || 0 }}%</span>
            <el-tag type="primary" v-if="item.resourceResp.resourceType === 1"
              >视频</el-tag
            >
            <el-tag type="warning" v-if="item.resourceResp.resourceType === 3"
              >文档</el-tag
            >
            <el-tag type="success" v-if="item.resourceResp.resourceType === 4"
              >图片</el-tag
            >
          </div>
        </div>
      </div>
    </div>
    <div slot="footer">
      <el-button @click="handleClose">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { CourseView } from "@/api/course/progress";
export default {
  name: "ProgressDetail",
  data() {
    return {
      courseData: {},
      activeCharpter: "",
      chapterList: [],
      visible: false,
    };
  },
  methods: {
    async getChapter() {
      const res = await CourseView({
        courseId: this.courseData.courseId,
        userId: this.courseData.userId,
      });
      if (res.code === 200) {
        this.chapterList = res.data.chapterRespList || [];
        if (this.chapterList.length) {
          this.activeCharpter = this.chapterList[0];
        }
      }
    },
    clickCharpter(item) {
      this.activeCharpter = item;
    },
    show(data) {
      this.courseData = data;
      this.getChapter();
      this.visible = true;
    },
    handleClose() {
      this.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  display: flex;
  border: 1px solid #ebeef5;
  height: 545px;
  .left {
    width: 30%;
    height: 100%;
    border-right: 1px solid #ebeef5;
    .header {
      width: 100%;
      padding: 12px;
      font-weight: bold;
      border-bottom: 1px solid #ebeef5;
    }
    .item {
      cursor: pointer;
      width: 100%;
      padding: 12px;
      border-bottom: 1px solid #ebeef5;
    }
    .acitve-item {
      color: #409eff;
      background-color: #ecf5ff;
    }
  }
  .right {
    flex: 1;
    .header {
      width: 100%;
      padding: 12px;
      font-weight: bold;
      border-bottom: 1px solid #ebeef5;
    }
    .item {
      display: flex;
      justify-content: space-between;
      width: 100%;
      padding: 12px;
      border-bottom: 1px solid #ebeef5;
    }
    .el-tag {
      margin-left: 10px;
    }
  }
}
</style>